import Vue from 'vue'
import VueRouter from 'vue-router'

import login from "../pages/one/login/login.vue"
import register from "../pages/one/register/register.vue"
import index from "../pages/one/index/index.vue"
import detail from "../pages/one/detail/detail.vue"
import search from "../pages/one/search/search.vue"
import foodList from "../pages/one/foodList/foodList.vue"
import site from "../pages/one/site/site.vue"
import pay from "../pages/one/pay/pay.vue"
import order from "../pages/one/order/order.vue"
import confirm from "../pages/one/confirm/confirm.vue"
import addSite from "../pages/one/addSite/addSite.vue"

import home from "../pages/two/home/home.vue"
import cate from "../pages/two/cate/cate.vue"
import shop from "../pages/two/shop/shop.vue"
import mine from "../pages/two/mine/mine.vue"


Vue.use(VueRouter)

const routes = [
  {path: '/login',name: '手机登录',component: login},
  {path: '/register',name: '手机注册',component: register},
  {path: '/index',name: '',component: index,
  children:[
    {path:"home",component:home,name:"小U商城"},
    {path:"cate",component:cate,name:"商品分类"},
    {path:"shop",component:shop,name:"购物车"},
    {path:"mine",component:mine,name:"会员中心"},
    ]
  },
  {path:"/pay",component:pay,name:"支付"},
  {path: '/detail',name: '商品详情',component: detail},
  {path: '/search',name: '商品搜索',component: search},
  {path: '/foodList',name: '商品列表',component: foodList},
  {path: '/site',name: '地址管理',component: site},
  {path: '/confirm',name: '确认订单',component: confirm},
  {path: '/order',name: '订单生成',component: order},
  {path: '/addSite',name: '地址添加',component: addSite},
  {path:"*",component:login}
]

const router = new VueRouter({
  routes
})
router.beforeEach((to,from,next)=>{
  if(to.path=="/login"||to.path=="/register"){
    next()
  }else if(localStorage.getItem("user")){
    next()
    return
  }
})

export default router
